//
//  MyClassRecord.m
//  HTT
//
//  Created by admin on 15/11/27.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "MyClassRecord.h"
@implementation MyClassRecord
+ (void)updateMyClassRecord:(NSArray *)myClassRecordArray{
    [myClassRecordArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        MyClassRecord *myClassRecord = (MyClassRecord *)obj;
        CourseRecord *courseRecord = [CourseRecord findFirstByAttribute:@"crId" withValue:myClassRecord.crId];
        if (!courseRecord) {
            [[myClassRecord toCourseRecord] saveUpdate];
        }else{
                courseRecord.crId = myClassRecord.crId;
                courseRecord.studentName = myClassRecord.studentName;
                courseRecord.cgcId = myClassRecord.cgcId;
                courseRecord.cgId = myClassRecord.cgId;
                courseRecord.crAccess = myClassRecord.crAccess;
                courseRecord.crAccessContent = myClassRecord.crAccessContent;
                courseRecord.crDate = myClassRecord.crDate;
                courseRecord.crStartTime = myClassRecord.crStartTime;
                courseRecord.crEndTime = myClassRecord.crEndTime;
                courseRecord.crTchSummary = myClassRecord.crTchSummary;
                courseRecord.studentPhoto = myClassRecord.studentPhoto;
                courseRecord.studentId = myClassRecord.studentId;
                courseRecord.cgAddress = myClassRecord.cgAddress;
                courseRecord.cgCount = myClassRecord.cgCount;
                courseRecord.cgRemainCount = myClassRecord.cgRemainCount;
                courseRecord.cgStartTime = myClassRecord.cgStartTime;
                courseRecord.cgcDate = myClassRecord.cgcDate;
                courseRecord.cgcStartTime = myClassRecord.cgcStartTime;
                courseRecord.cgcStatus = myClassRecord.cgcStatus;
                courseRecord.gradeName = myClassRecord.gradeName;
                courseRecord.courseName = myClassRecord.courseName;
                courseRecord.tchId = myClassRecord.tchId;
                courseRecord.cgcStopTime = myClassRecord.cgcStopTime;
            courseRecord.teacherName = myClassRecord.teacherName;
            courseRecord.teacherPhoto = myClassRecord.teacherPhoto;
            [XLCoreDataManager save];
        }
        
    }];
}
- (CourseRecord *)toCourseRecord{
    CourseRecord *courseRecord = [CourseRecord createEntity];
    courseRecord.crAccess = self.crAccess;
    courseRecord.crAccessContent = self.crAccessContent;
    courseRecord.crDate = self.crDate;
    courseRecord.crEndTime = self.crEndTime;
    courseRecord.crStartTime = self.crStartTime;
    courseRecord.crTchSummary = self.crTchSummary;
    courseRecord.cgcDate = self.cgcDate;
    courseRecord.cgcId = self.cgcId;
    courseRecord.cgCount = self.cgCount;
    courseRecord.cgcStartTime = self.cgcStartTime;
    courseRecord.cgcStatus = self.cgcStatus;
    courseRecord.cgcStopTime = self.cgcStopTime;
    courseRecord.cgId = self.cgId;
    courseRecord.cgRemainCount = self.cgRemainCount;
    courseRecord.cgStartTime = self.cgStartTime;
    courseRecord.studentId = self.studentId;
    courseRecord.studentName = self.studentName;
    courseRecord.studentPhoto = self.studentPhoto;
    courseRecord.tchId =self.tchId;
    courseRecord.gradeName = self.gradeName;
    courseRecord.courseName = self.courseName;
    courseRecord.crId = self.crId;
    courseRecord.cgAddress = self.cgAddress;
    courseRecord.teacherPhoto = self.teacherPhoto;
    courseRecord.teacherName = self.teacherName;
    return courseRecord;
}
+ (MyClassRecord *)toMyClassRecord:(CourseRecord *)coureRecord{
    MyClassRecord *myClssRecord = [[MyClassRecord alloc] init];
    myClssRecord.crAccess = coureRecord.crAccess;
    myClssRecord.crAccessContent = coureRecord.crAccessContent;
    myClssRecord.crDate = coureRecord.crDate;
    myClssRecord.crEndTime = coureRecord.crEndTime;
    myClssRecord.crStartTime = coureRecord.crStartTime;
    myClssRecord.crTchSummary = coureRecord.crTchSummary;
    myClssRecord.cgcDate = coureRecord.cgcDate;
    myClssRecord.cgcId = coureRecord.cgcId;
    myClssRecord.cgCount = coureRecord.cgCount;
    myClssRecord.cgcStartTime = coureRecord.cgcStartTime;
    myClssRecord.cgcStatus = coureRecord.cgcStatus;
    myClssRecord.cgcStopTime = coureRecord.cgcStopTime;
    myClssRecord.cgId = coureRecord.cgId;
    myClssRecord.cgRemainCount = coureRecord.cgRemainCount;
    myClssRecord.cgStartTime = coureRecord.cgStartTime;
    myClssRecord.studentId = coureRecord.studentId;
    myClssRecord.studentName = coureRecord.studentName;
    myClssRecord.studentPhoto = coureRecord.studentPhoto;
    myClssRecord.tchId =coureRecord.tchId;
    myClssRecord.gradeName = coureRecord.gradeName;
    myClssRecord.courseName = coureRecord.courseName;
    myClssRecord.crId = coureRecord.crId;
    myClssRecord.cgAddress = coureRecord.cgAddress;
    myClssRecord.teacherName = coureRecord.teacherName;
    myClssRecord.teacherPhoto = coureRecord.teacherPhoto;
    return myClssRecord;
}
+ (NSArray *)toMyClassRecords:(NSArray *)courseRecords{
    NSMutableArray *array = [NSMutableArray array];
    [courseRecords enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        CourseRecord *course = (CourseRecord *)obj;
        [array addObject:[MyClassRecord toMyClassRecord:course]];
    }];
    return [NSArray arrayWithArray:array];
}
@end
